﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using QuanLyBanHang.OBJECT;

namespace QuanLyBanHang.DAL
{
    class DalNhapXuatKho
    {
        public static DataTable LoadProducts()
        {
            string sql1 = "select MaHang, TenHang from HangHoa";
            DataTable dt1 = DataHelper.Load(sql1);
            return dt1;
        }

        public static DataTable GetProductsName(string MaHang)
        {
            string sql2 = "select TenHang from HangHoa where MaHang = '" + MaHang + "'";
            DataTable dt2 = DataHelper.Load(sql2);
            return dt2;
        }

        public static DataTable LoadStaff()
        {
            string sql3 = "select MaNV, Ten from NhanVien";
            DataTable dt3 = DataHelper.Load(sql3);
            return dt3;
        }

        public static int InsertBillIn(ObjHoaDonNhap obj)
        {
            SqlParameter[] para = new SqlParameter[3];
            string[] names = { "MaHDN", "MaNV", "NgayNhap" };
            object[] values = { obj.MaHDN, obj.MaNV, obj.NgayNhap };
            for (int i = 0; i < para.Length; i++)
            {
                para[i] = new SqlParameter(names[i], values[i]);
            }
            int thucthi = DataHelper.Update(para, "spInsertHoaDonNhap");
            return thucthi;
        }

        public static int InsertBillInDetail(ObjCT_HoaDonNhap obj)
        {
            SqlParameter[] para = new SqlParameter[3];
            string[] names = { "MaHDN", "MaHang", "SoLuong" };
            object[] values = { obj.MaHDN, obj.MaHang, obj.SoLuong };
            for (int i = 0; i < para.Length; i++)
            {
                para[i] = new SqlParameter(names[i], values[i]);
            }
            int thucthi = DataHelper.Update(para, "spInsertCT_HoaDonNhap");
            return thucthi;
        }

        public static int InsertBillOut(ObjXuatKho obj)
        {
            SqlParameter[] para = new SqlParameter[3];
            string[] names = { "MaXuatKho", "MaNV", "NgayXuat" };
            object[] values = { obj.MaXuatKho, obj.MaNV, obj.NgayXuat };
            for (int i = 0; i < para.Length; i++)
            {
                para[i] = new SqlParameter(names[i], values[i]);
            }
            int thucthi = DataHelper.Update(para, "spInsertXuatKho");
            return thucthi;
        }

        public static int InsertBillOutDetail(ObjCT_XuatKho obj)
        {
            SqlParameter[] para = new SqlParameter[3];
            string[] names = { "MaXuatKho", "MaHang", "SoLuong" };
            object[] values = { obj.MaXuatKho, obj.MaHang, obj.SoLuong };
            for (int i = 0; i < para.Length; i++)
            {
                para[i] = new SqlParameter(names[i], values[i]);
            }
            int thucthi = DataHelper.Update(para, "spInsertCT_XuatKho");
            return thucthi;
        }
    }
}
